home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Core Utilities / SystemIdle.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-21  |  2.7 KB  |  85 lines  |  [TEXT/CWIE]

  1. #ifndef __SYSTEMIDLE__
  2. #define __SYSTEMIDLE__
  3.  
  4. #ifndef __MACTYPES__
  5. #include <MacTypes.h>
  6. #endif
  7. #ifndef __MIXEDMODE__
  8. #include <MixedMode.h>
  9. #endif
  10. #ifndef __EVENTS__
  11. #include <Events.h>
  12. #endif
  13.  
  14. #if PRAGMA_ONCE
  15. #pragma once
  16. #endif
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. #if PRAGMA_STRUCT_ALIGN
  23.     #pragma options align=mac68k
  24. #elif PRAGMA_STRUCT_PACKPUSH
  25.     #pragma pack(push, 2)
  26. #elif PRAGMA_STRUCT_PACK
  27.     #pragma pack(2)
  28. #endif
  29.  
  30. struct EventParams {
  31.     EventMask                        mask;            // mask to use when polling
  32.     EventRecord                        event;            // copy of last event received
  33.     short                            filler;            // 
  34.     RgnHandle                        mouseRgn;        // mouseRgn for system to use
  35.     UInt32                            sleep;            // sleep time for WNE
  36.     UInt32                            wakeTime;        // time to call threads
  37.     long                            refcon;            // use as you like
  38. };
  39. typedef struct EventParams            EventParams;
  40. typedef EventParams *                EventParamsPtr;
  41.  
  42.  
  43. typedef CALLBACK_API( OSErr , SystemEventHandlerProcPtr )(EventRecord *theEvent, UInt32 *sleepTime, RgnHandle *mouseRgn, long refcon);
  44. typedef STACK_UPP_TYPE(SystemEventHandlerProcPtr)                     SystemEventHandlerUPP;
  45. enum { uppSystemEventHandlerProcInfo = 0x00003FE0 };                     /* pascal 2_bytes Func(4_bytes, 4_bytes, 4_bytes, 4_bytes) */
  46. #define NewSytemIdleProcProc(userRoutine)                         (AESystemEventHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSystemEventHandlerProcInfo, GetCurrentArchitecture())
  47. #define CallSystemEventHandlerProc(userRoutine, theEvent, sleepTime, mouseRgn, refcon)  CALL_FOUR_PARAMETER_UPP((userRoutine), uppSystemEventHandlerProcInfo, (theEvent), (sleepTime), (mouseRgn), (refcon))
  48.  
  49. typedef CALLBACK_API( OSErr , CalcSleepProcPtr )(long *sleepTime, RgnHandle *mouseRgn, long refcon);
  50. typedef STACK_UPP_TYPE(CalcSleepProcPtr)                     CalcSleepUPP;
  51. enum { uppCalcSleepProcInfo = 0x00000FE0 };                 /* pascal 2_bytes Func(4_bytes, 4_bytes, 4_bytes) */
  52. #define CallCalcSleepProc(userRoutine, sleepTime, mouseRgn, refcon)  CALL_THREE_PARAMETER_UPP((userRoutine), uppSystemEventHandlerProcInfo, (theEvent), (sleepTime), (mouseRgn), (refcon))
  53.  
  54.  
  55. EXTERN_API( OSErr )
  56. InstallSystemEventHandler        (SystemEventHandlerUPP             handler,
  57.                                  long                             handlerRefcon,
  58.                                  EventParamsPtr                    eventParams);
  59.  
  60. EXTERN_API( OSErr )
  61. GetSystemEventHandler            (SystemEventHandlerUPP*         handler,
  62.                                  long*                             handlerRefcon);
  63.  
  64. EXTERN_API( OSErr )
  65. SystemIdle                        (void);
  66.  
  67. EXTERN_API( Boolean )
  68. XWaitNextEvent                    (EventMask                 eventMask,
  69.                                  EventRecord *            theEvent,
  70.                                  UInt32                 sleep,
  71.                                  RgnHandle                 mouseRgn);
  72.  
  73. #if PRAGMA_STRUCT_ALIGN
  74.     #pragma options align=reset
  75. #elif PRAGMA_STRUCT_PACKPUSH
  76.     #pragma pack(pop)
  77. #elif PRAGMA_STRUCT_PACK
  78.     #pragma pack()
  79. #endif
  80.  
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84.  
  85. #endif __SYSTEMIDLE__